/*************************************************************************
	> File Name: P1327.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-02-11 17:38:24
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_N 100000
int a[MAX_N + 5], b[MAX_N + 5];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        b[i] = a[i];
    }
    sort(b, b + n);
    unordered_map<int, int> mp;
    for (int i = 0; i < n; i++) {
        mp[b[i]] = i;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        while (a[i] != b[i]) {
            int ind = mp[a[i]];
            swap(a[i], a[ind]);
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}
